package fr.emn.integration.synthese.controle;

import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Observable;
import java.util.Observer;

import javax.swing.JButton;

import fr.emn.integration.synthese.abstraction.Cours;
import fr.emn.integration.synthese.presentation.EleveBDDialog;
import fr.emn.integration.synthese.presentation.ModifEleveDialog;

public class ControlJButtonEditEleve implements ActionListener, Observer {

	private Cours modele;
	private JButton button;
	private Frame parent;

	public ControlJButtonEditEleve(Frame parent, Cours modele, JButton button) {
		this.modele = modele;
		this.button = button;
		this.parent = parent;
		this.button.setEnabled(false);
		

	}

	@Override
	public void actionPerformed(ActionEvent e) {
		ModifEleveDialog eleveDialog = new ModifEleveDialog(parent, modele, true);
		eleveDialog.setVisible(true);
	}

	@Override
	public void update(Observable arg0, Object arg1) {
		Integer iMessage = (Integer) arg1;
		
		if (iMessage == Cours.CHANGEMENT_ELEVE_COURANT) {
			if (this.modele.getEleveCourante()!=null) {
				button.setEnabled(true);
			}
			else {
				button.setEnabled(false);
			}
		}
		
	}
}